/*
 * @Author: H.
 * @Date: 2021-12-13 14:07:46
 * @LastEditTime: 2021-12-13 15:50:42
 * @Description:
 */
import * as echarts from 'echarts'
import chinaMapData from '../data/china.json'

// 注册中国地图
echarts.registerMap('china', chinaMapData)

export default function (el: HTMLElement) {
  const echartInstance = echarts.init(el)

  const setOptions = (options: echarts.EChartsOption) => {
    echartInstance.setOption(options)
  }

  const updateSize = () => {
    echartInstance.resize()
  }

  window.addEventListener('resize', () => {
    echartInstance.resize()
  })

  return {
    echartInstance,
    setOptions,
    updateSize
  }
}
